<?php

namespace Admin\Controller;

/**
 * APP配置
 */
class ConfigController extends CommonController {

    /**
     * 编辑
     */
    public function index(){
        $params = array(
            'showpage' => 10
        );
        $redata = D('Config')->listData($params);
        $this->assign('list',$redata['list']);
        $this->assign('page',$redata['page']);
        $this->display();
    }
    /**
     * 保存
     */
    public function saveversion(){
        $id = I('POST.config_id');
        $Config = M('config');
        $data = $Config -> create();
        $data['version_time'] = time();
        $Res = $Version -> save($data);
        if($Res>0){
            $this->success('操作成功！',U('index'));
        }else{
            $this->error('操作失败！');
        }
    }
    /**
     * 新建
     */
    public function addconfig(){
        $config_name = I('POST.config_name');
        $config_value = I('POST.config_value');
        $config_remark = I('POST.config_remark');
        $data = array(
            'config_name' => $config_name,
            'config_value' => $config_value,
            'config_remark' => $config_remark,
            'config_time' => time()
        );
        $Res = D('config')->addData($data);
        if($Res){
            $this->success('添加成功！',U('index'));
        }else{
            $this->error('添加失败！');
        }
    }
    /**
     * 删除
     */
    public function delconfig(){
        $config_id = I('POST.id');

        if (empty($config_id)) $this->error('请选择要操作的对象！');

        $map = array(
            'config_id' => $config_id
        );
        $Res = D('config')->deleteData($map);
        if($Res){
            $this->success('删除成功！',U('index'));
        }else{
            $this->error('删除失败！');
        }
    }
    /**
     * 修改
     */
    public function updconfig(){
        $config_id = I('POST.config_id');
        $config_name = I('POST.config_name');
        $config_value = I('POST.config_value');
        $config_remark = I('POST.config_remark');
        $data = array(
            'config_id' => $config_id,
            'config_name' => $config_name,
            'config_value' => $config_value,
            'config_remark' => $config_remark,
            'config_time' => time()
        );
        $map = array(
            'config_id' => $config_id
        );
        $Res = D('config')->editData($map, $data);
        if($Res>0){
            $this->success('操作成功！',U('index'));
        }else{
            $this->error('操作失败！');
        }
    }
}